from django.db import models
from rest_framework import settings
from rest_framework.serializers import Serializer

from verifications import constants


class BaseModel(models.Model):
    """为模型类补充字段"""
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        abstract = True  # 说明是抽象模型类, 用于继承使用，数据库迁移时不会创建BaseModel的表


# def generate_save_user_token(openid):
#     """
#     生成保存用户数据的token
#     :param openid: 用户的openid
#     :return: token
#     """
#     serializer = Serializer(settings.SECRET_KEY, expires_in=constants.SAVE_QQ_USER_TOKEN_EXPIRES)
#     data = {'openid': openid}
#     token = serializer.dumps(data)
#     return token.decode()